#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

typedef int Position;
typedef struct LNode *List;
struct LNode
{
    double *Data;
    Position Last;
    int Length;
};

List Make_Empty(int Element_number)
{
    List L;
    L = (List)malloc(sizeof(struct LNode));
    L->Data = (double*)malloc(sizeof(double) * Element_number);
    L->Last = -1;
    L->Length = Element_number;
    return L;
}

bool Insert(List L, double X)
{
    if (L->Last + 1 == L->Length)
    {
        printf("List is full !");
        return false;
    }
    else
    {
        L->Data[++L->Last] = X;
        return true;
    }
}

/*
List Delete(List L, double minD, double maxD)
{
    double *new_double_vector = (double*)malloc(sizeof(double) * L->Last);
    Position new_index = 0;

    for (Position index = 0; index <= L->Last; index++)
    {
        if (!(L->Data[index] < maxD && L->Data[index] > minD))
            new_double_vector[new_index++] = L->Data[index];
    }

    L->Data = new_double_vector;

    return L;
}
*/

List Delete(List L, double minD, double maxD)
{
    Position index = 0;
    for (; index <= L->Last; index++)
        if (L->Data[index] > minD && L->Data[index] < maxD)
            break;
    Position p = index;

    for (; index <= L->Last; index++)
        if (!(L->Data[index] > minD && L->Data[index] < maxD))
            L->Data[p++] = L->Data[index];
    L->Last = p - 1;

    return L;
}

int main()
{
    List example_list;
    double number;

    example_list = Make_Empty(10);

    for (;;)
    {
        printf("Enter the number to input(0 to finish) : ");
        scanf("%lf", &number);
        if (number == 0)
            break;
        if (Insert(example_list, number))
            printf("Insert success !\n");
        else
            break;
    }
    printf("\n");

    example_list = Delete(example_list, 5, 10);

    for (int index = 0; index <= example_list->Last; index++)
        printf("%lf ", example_list->Data[index]);

    return 0;
}

